"""
Nibbles the video game.

Copyright (c) 2014 Grant Jenks
http://www.grantjenks.com/

Exercises
1. Change the colors.
2. Increase the size of the playing area.
3. Change the snake speed.
4. Make the food jump randomly.
5. Change the controls to (w, a, s, d)
6. Add diagonals.
7. Add high score.
8. Make the game boundaries into walls.
"""

import sys, pygame
from random import randrange
from pygame.locals import KEYDOWN, QUIT
from itertools import count

size = width, height = 480, 480
down = (0, 10)

pygame.init()
screen = pygame.display.set_mode(size)

snake_dir = down
snake = [pygame.Rect(10, 10 + value * 10, 10, 10) for value in range(20)]
foreground, background = (255, 255, 255), (0, 0, 0)

for counter in count():
    event = pygame.event.poll()

    if event.type == QUIT:
        pygame.quit()
        sys.exit()

    next = snake[-1].move(snake_dir)
    snake.append(next)

    screen.fill(background)
    for rect in snake:
        pygame.draw.rect(screen, foreground, rect)
        
    pygame.display.flip()
